package homework7_22;

import java.util.ArrayList;
import java.util.Collections;

public class doudizhu {
    public static void main(String[] args) {
        ArrayList<String> poker = preparePoker();
        System.out.println("初始牌组：" + poker);
        Collections.shuffle(poker);
        System.out.println("洗牌后牌组：" + poker);
        Player p1 = new Player("老王");
        Player p2 = new Player("老李");
        Player p3 = new Player("老六");
        ArrayList<String> dipai = dealAndSort(poker, p1, p2, p3);
        Collections.sort(p1.getPoker(), new Player.Comparator());
        Collections.sort(p2.getPoker(), new Player.Comparator());
        Collections.sort(p3.getPoker(), new Player.Comparator());
        Collections.sort(dipai, new Player.Comparator());
        printPlayerCards(p1);
        printPlayerCards(p2);
        printPlayerCards(p3);
        System.out.println("底牌:" + dipai);
    }
    public static ArrayList<String> preparePoker() {
        ArrayList<String> poker = new ArrayList<String>();
        String[] colors = {"♠", "♣", "♦", "♥"};
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        poker.add("大王");
        poker.add("小王");

        for (String number : numbers) {
            for (String color : colors) {
                poker.add(color + number);
            }
        }
        return poker;
    }
    public static ArrayList<String> dealAndSort(ArrayList<String> poker, Player p1, Player p2, Player p3) {
        ArrayList<String> dipai = new ArrayList<String>();

        for (int i = 0; i < poker.size(); i++) {
            String p = poker.get(i);
            if (i >= 51) {
                dipai.add(p);
            } else if (i % 3 == 0) {
                p1.getPoker().add(p);
            } else if (i % 3 == 1) {
                p2.getPoker().add(p);
            } else if (i % 3 == 2) {
                p3.getPoker().add(p);
            }
        }

        return dipai;
    }
    public static void printPlayerCards(Player player) {
        Collections.sort(player.getPoker(), new Player.Comparator());
        System.out.println(player.getName() + "的牌:" + player.getPoker());
    }
}